package jsi.spring;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

public class OsobaDaoImpl implements OsobaDao {
	private HibernateTemplate ht;

	public void setSessionFactory(SessionFactory sf) {
		ht = new HibernateTemplate(sf);
	}

	public Osoba findOsobaByName(String imie) {
		List l = ht.findByNamedParam("from Osoba o where o.imie = :imie",
				"imie", imie);
		if (l.size() == 0)
			return null;
		else
			return (Osoba) l.get(0);
	}

	public void saveOsoba(Osoba o) {
		ht.save(o);
	}

	public Osoba mergeOsoba(Osoba o) {
		return (Osoba) ht.merge(o);
	}
}
